<?php
session_start();
require 'init.php';
require 'FunctionsClass.php';
require 'CommonQueryClass.php';
require 'SiteSettingsClass.php';
require 'PageClass.php';
require 'PageCategoryClass.php';
require 'PageSubsClass.php';
require 'PageResourcesClass.php';
require 'RelatedPagesClass.php';
require 'PageNavigatorClass.php';
require 'ParentPatner.php';
require 'EventCalendar.php';
$script="";
$fxn = new Utils();
$con = new MySQLConnect($hostname_conn, $username_conn, $password_conn); 
$cquery = new CommonQuery($con,$conn,$database_conn);

$page=0;
$c_offset=0;
$p_offset=0;
foreach($_GET as $key=>$val) {
    $$key=$val;

}

$HOME_URL=substr($_SERVER["PHP_SELF"], 0,strpos($_SERVER["PHP_SELF"], "/", 1))."/";

$fxn->ADMIN_HOME = $HOME_URL."admin/index.php?page=content&";


define('PERPAGE',10);

$cquery->loadSiteDetails(@$_GET['site']);

$SITE_ID = $_SESSION["SITE_ID"];
$SITE_NAME =$_SESSION["SITE_NAME"];

$site = new SiteSettings($cquery->getSiteSettings($SITE_ID));

if(isset($_GET["parent"]) && !isset($_GET["page"]))
$page=$cquery->sitePageUrl();


$fxn->USE_URL_PARAM = $site->USE_URL_PARAM;
$cquery->SITENAME=$site->SITENAME;
$USE_URL_PARAM = $fxn->USE_URL_PARAM;
$cquery->fxn= $fxn;
$SITE_LOGO_URL = $site->SITE_URL."resources/".$cquery->getResourceDetails(@$site->SITELOGO);
$c_offset = $fxn->validateNum($c_offset, 0);
$p_offset =$fxn->validateNum($p_offset, 0);
$cquery->SITETITLE= $site->SITE_TITLE;
if(isset($_GET["error"])){
    include 'theme/'.$site->CURRENTTHEME.'/template/error.php';
}
else if(isset($page) && strlen($page)>1){
if($page=="search") {
    include 'theme/'.$site->CURRENTTHEME.'/template/searchtemp.php';
}else if($page=='rss' || isset($_GET["rss"])) {
    $page = $_GET["rss"];
    $row = $cquery->getContentDetails($page);

    $pages = new Page($row);
    $pages->fxn= $fxn;
    $cquery->LIMIT_PER = 400;
    $rowp=$cquery->getContentByCat($pages->pageid,0);
    $cquery->LIMIT_PER = 40;
    $pages->setsubPage($rowp);
    include 'theme/default/template/rss.php';
}
else if($cquery->validatePage($page,$SITE_NAME)) {

    $cquery->updatePageHits($page);
    $cquery->LIMIT_PER = PERPAGE;
    $row=array();
    //Get all the Attributes of the page
    //Initialising the page

    $row = $cquery->getContentDetails($page);
    

    $pages = new Page($row);
     $pages->fxn= $fxn;
    $listTypeComment= $cquery->getListType($page);
$listTypeComment= explode(":::", $listTypeComment);
    $pages->listType=$listTypeComment[0];
    $pages->allowComment=$listTypeComment[1];


    $recordOffset_c = $c_offset*PERPAGE; //start position for a category
    $recordOffset_p = $p_offset*PERPAGE; //Start Position for a page
    $rowc= $cquery->getCategoryByParent($pages->categoryid,$recordOffset_c);

    $cpage =$_SERVER["PHP_SELF"];
    $total =$cquery->currentTotal;
    $pages->setpageCategories($rowc);

    if(!$fxn->checkOutOfRange($recordOffset_c, $total)){
        $c_offset=0;
        $recordOffset_c=0;
    }
$listname  =$fxn->urlFriendly($cquery->getListTypeName($pages->listType), "_");
    $pages->setParentPartner($cquery->getParentPartners($pages->categoryid,$pages->cattype));
    
    $pages->parentName = $cquery->pageParent;
    $catNav = new PageNavigator($cpage,$total,'c_offset',PERPAGE,$recordOffset_c,5,$fxn->USE_URL_PARAM,"&page=".$page);
 
  //Get list of all Sub pages
  $rowp=$cquery->getContentByCat($pages->pageid,$recordOffset_p);

    $pages->setsubPage($rowp);
    $total_p = $cquery->currentTotal;

    if(! $fxn->checkOutOfRange($recordOffset_p, $total_p)) {
        $p_offset=0;
        $recordOffset_p=0;
    }

    $pageNav  = new PageNavigator($cpage,$total_p,'p_offset',PERPAGE,$recordOffset_p,5,$fxn->USE_URL_PARAM,"&page=".$page);

    //Get List of Resourses ie images, videos, audios of the page
    $rowr= $cquery->getContentResource($page,0,"yes");
    $pages->setPageResources($rowr);

    //Get a List of all related pages
    $rowRelatedPages =  $cquery->getRelatedPagesList($page);
    $pages->setRelatedPages($rowRelatedPages);

    $pages->includedPagesList=$cquery->getPageForm($pages->pageid);
   $whereWeAre= $cquery->whereWeAre($pages->categoryid, $pages->cattype, $pages->title, $pages->pageid, $pages->directlink, $pages->banner);

    include "theme/".$site->CURRENTTHEME."/template/main_page.php";
}else {
       

    include 'theme/'.$site->CURRENTTHEME.'/template/home_page.php';
  
}}else    include 'theme/'.$site->CURRENTTHEME.'/template/home_page.php';

?>
